import {search } from '../services/user';

export default {
  namespace: 'userSelect',

  state: {
    searchUsers: []
  },

  effects: {
    *search({ payload }, { call, put }){
      let response = yield call(search, {...payload});
      if(response.code === 0){
        yield put({
          type:'setSearchUsers',
          payload: response.data
        })
      }else{
        yield put({
          type:'setSearchUsers',
          payload: []
        })
      }
    }, 
  },

  reducers: {
    setSearchUsers(state, action){
      return {
        ...state,
        searchUsers: action.payload
      }
    }
  },
};
